package me.green.ui.dialog;

import me.green.ui.global.UIStyle;

import javax.swing.*;
import java.awt.*;

/**
 * 关于窗口
 *
 * @author green
 */
public class AboutDialog extends JDialog {

    private static final long serialVersionUID = 1L;

    private JPanel jContentPane = null;

    private JLabel labVersion = null;
    private JLabel labName = null;
    private JLabel labEmail = null;
    private JButton btnClose = null;


    public AboutDialog(Frame owner, boolean model) {
        super(owner, model);
        initialize();
        this.setLocationRelativeTo(owner);
        this.setVisible(true);
    }

    /**
     * 初始化
     *
     * @return void
     */
    private void initialize() {
        this.setSize(510, 300);
        this.setTitle("关于");
        this.setResizable(false);
        this.setIconImage(new ImageIcon(this.getClass().getResource("/pic/tray.png")).getImage());
        this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
        this.setContentPane(getJContentPane());
    }

    /**
     * 获取关于主面板
     *
     * @return javax.swing.JPanel
     */
    private JPanel getJContentPane() {
        if (jContentPane == null) {
            labEmail = new JLabel();
            labEmail.setBounds(new Rectangle(120, 105, 350, 35));
            labEmail.setFont(UIStyle.defaultFont());
            labEmail.setText("邮　箱: green1893@gmail.com");

            labName = new JLabel();
            labName.setBounds(new Rectangle(120, 60, 300, 35));
            labName.setFont(UIStyle.defaultFont());
            labName.setText("开发者: green");

            labVersion = new JLabel();
            labVersion.setBounds(new Rectangle(120, 15, 300, 35));
            labVersion.setFont(UIStyle.defaultFont());
            labVersion.setText("版　本：v1.4");

            jContentPane = new JPanel();
            jContentPane.setLayout(null);
            jContentPane.setSize(new Dimension(500, 220));

            jContentPane.add(labVersion, null);
            jContentPane.add(labName, null);
            jContentPane.add(labEmail, null);
            jContentPane.add(getBtnClose(), null);
        }
        return jContentPane;
    }

    /**
     * 获取关闭按钮
     *
     * @return javax.swing.JButton
     */
    private JButton getBtnClose() {
        if (btnClose == null) {
            btnClose = new JButton();
            int btnWidth = 100;
            // 按钮居中显示
            int x = (this.getWidth() - 100) / 2;
            btnClose.setBounds(new Rectangle(x, 165, btnWidth, 42));
            btnClose.setFont(UIStyle.defaultFont());
            btnClose.setText("确定");
            btnClose.addActionListener(new java.awt.event.ActionListener() {
            	@Override
                public void actionPerformed(java.awt.event.ActionEvent e) {
                    AboutDialog.this.dispose();
                }
            });
        }
        return btnClose;
    }
}
